package com.yixun.qfbao.hander;

import com.yixun.qfbao.model.enums.SystemIdEnum;
import com.yixun.qfbao.util.WxAccessTokenCacheUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.api.service.PremisesApiService;
import com.yixun.qfbao.apidto.AddOrEditPremisesReqDto;
import com.yixun.qfbao.apidto.AddOrEditPremisesResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.AddOrEditPremisesReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 * （12）	修改楼盘
 * 
 * @author jzliu
 *		
 */
@Service("editPremisesHander")
public class EditPremisesHander extends CommonAbstractHander {
	private static Logger logger= LoggerFactory.getLogger(EditPremisesHander.class);
	
	@Autowired
	private PremisesApiService premisesService;
	@Autowired
    private WxAccessTokenCacheUtils wxAccessTokenCacheUtils;
	
	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		AddOrEditPremisesReqVo req = (AddOrEditPremisesReqVo)reqDto;
		AddOrEditPremisesReqDto reqDto1 = req.getParams();
		BaseResponseDTO<AddOrEditPremisesResDto> res = new BaseResponseDTO<AddOrEditPremisesResDto>();
		AddOrEditPremisesResDto resDto = new AddOrEditPremisesResDto();
		try {
		    String agencyAccessToken = wxAccessTokenCacheUtils.getAccessToken(reqDto1.getCompanyUuid(), SystemIdEnum.AGENCY_h5.getCode(), reqDto1.getDomain());
			reqDto1.setAgencyAccessToken(agencyAccessToken);
		    resDto = premisesService.editPremises(reqDto1);
		} catch (Exception e) {
			logger.error("EditPremisesHander error: {}", e);
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg("修改楼盘失败!");
		}
		res.setResData(resDto);
		res.setResult(resDto.getResult());
		return res;
	}
	
}
